package com.example.shop_2304.utils

import android.os.Bundle
import android.webkit.WebChromeClient
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.isVisible
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.base.mvvm.BaseViewActivity
import com.example.shop_2304.R
import com.example.shop_2304.databinding.ActivityWebViewBinding

/**
 * 封装webview界面，多个请求(传过来的参数)，都可以在这个代码中展示
 */
@Route(path = "/app/WebViewActivity")
class WebViewActivity : BaseViewActivity<ActivityWebViewBinding>() {
    @JvmField
    @Autowired
    var url = ""//不公开     @JvmField就变成public

   // @Autowired(name = "") //当跳转页面的传入的参数名称  和  接收方接收的参数名称不一致 时可用name来重新命名  当一致时，name可省略
   // lateinit var url:String
    override fun initView() {
        ARouter.getInstance().inject(this)
       binding.wv.loadUrl(url)//加载内容
       binding.wv.webViewClient = WebViewClient()//在app内部显示
       var webChromeClient = object :WebChromeClient(){
           override fun onProgressChanged(view: WebView?, newProgress: Int) {
               super.onProgressChanged(view, newProgress)
               if(newProgress==100){
                   binding.pb.isVisible = false
               }
               binding.pb.progress = newProgress
           }
       }
       binding.wv.webChromeClient = webChromeClient//可显示进度条
       binding.wv.settings.javaScriptEnabled = true//webview页面上的都可点击

    }

    override fun initData() {

    }

    override fun getLayout(): Int  = R.layout.activity_web_view

}